import React from 'react'
import { Button, Table } from 'antd'
import { ColumnProps } from 'antd/lib/table'
import { formatTime } from '~/utils/utils'

const colums = ({ onClickDownLoadFile, setIsShowDeleteReason, recordData }: any): ColumnProps<any>[] => [
  {
    title: '序号',
    dataIndex: 'id',
    align: 'center',
    render: (_: any, record: any, index: number) => `${index + 1}`
  },
  {
    title: '上传人',
    dataIndex: 'createUserName',
    align: 'center'
  },
  {
    title: '上传单位',
    dataIndex: 'createCompanyName',
    align: 'center',
    key: 'age'
  },
  {
    title: '上传部门',
    dataIndex: 'createDepartmentName',
    align: 'center',
    key: 'age'
  },
  {
    title: '上传时间',
    dataIndex: 'createTime',
    align: 'center',
    key: 'age',
    render: (createTime: any) => <div>{formatTime(createTime)}</div>
  },
  {
    title: '文件名',
    dataIndex: 'fileName',
    align: 'center',
    key: 'age'
  },
  {
    title: '操作',
    key: 'age',
    align: 'center',
    render: (_: any, record: any) => (
      <>
        <Button type="primary" size="small" onClick={() => onClickDownLoadFile(record)}>
          下载
        </Button>
        <Button
          style={{ marginLeft: 10 }}
          type="primary"
          size="small"
          onClick={() => {
            recordData.current = record
            setIsShowDeleteReason(true)
          }}
        >
          删除
        </Button>
      </>
    )
  }
]

const WaitingList = ({
  waitCastItems,
  onClickVoidCertificate,
  onClickViewCertificate,
  setCertificateVisible,
  onClickDownLoadFile,
  setIsShowDeleteReason,
  recordData,
  onClickAddAttachmentList
}: any) => {
  return (
    <div>
      <Table
        rowKey="id"
        dataSource={waitCastItems}
        pagination={{
          size: 'default',
          total: waitCastItems.length,
          showSizeChanger: true,
          showQuickJumper: true,
          showTotal: total => `共 ${total} 条`
        }}
        bordered
        columns={colums({
          onClickViewCertificate,
          onClickVoidCertificate,
          setCertificateVisible,
          onClickDownLoadFile,
          setIsShowDeleteReason,
          recordData,
          onClickAddAttachmentList
        })}
      />
    </div>
  )
}

export default WaitingList
